﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using DTO;

namespace BUS
{
    public class DON_HANGBUS
    {
        public DON_HANGDAL kh = new DON_HANGDAL();
        public void DonHang_Them(DON_HANG k)
        {
            kh.DonHang_ThemDuLieu(k);
        }

        public void DonHang_Sua(DON_HANG k)
        {
            kh.DonHang_SuaDulieu(k);
        }

        public void DonHang_Xoa(int id)
        {
            kh.DonHang_XoaDuLieu(id);
        }

        public void DonHang_TrangThai(DON_HANG k)
        {
            kh.DonHang_CapNhatTrangThai(k);
        }

        public static DonHangCollection DonHang_LayTatCaCSDL()
        {
            int t = 0;
            DON_HANGDAL dh = new DON_HANGDAL();
            return dh.Get("where 1=1", 0, 1000, DonHangColumns.MA_DH.ToString(), "DESC", out t);
        }        

        public static DON_HANG GetByID(int iD)
        {
            int t = 0;
            DON_HANGDAL dh = new DON_HANGDAL();
            DonHangCollection donhangcollection = dh.Get("where " + DonHangColumns.MA_DH.ToString() + " = " + iD.ToString(), 0, 0,
                DonHangColumns.MA_DH.ToString(), "ASC", out t); // cần hiểu chổ này
            if (donhangcollection.Count == 1)
                return donhangcollection[0];
            return null;
        }

        public static string GetCha(int makhachhang)
        {
            int t = 0;
            DON_HANGDAL dh = new DON_HANGDAL();
            DonHangCollection donhangcollection = dh.Get("where " + DonHangColumns.MA_DH.ToString() + " = " + makhachhang.ToString(), 0, 0,
                DonHangColumns.MA_DH.ToString(), "ASC", out t);
            if (donhangcollection.Count == 1)
                return donhangcollection[0].MaDonHang.ToString();
            return null;
        }
    }
}
